from django.db import models

# Create your models here.
class Order(models.Model):
    payment_type_choice = (
        (1,'在线支付'),(2,'货到付款')
    )
    order_status = (
        (1,'未付款'),
        (1,'已付款'),
        (1,'未运输'),
        (1,'运输中'),
        (1,'交易成功'),
        (1,'交易关闭')
    )
    order_id = models.CharField(max_length=50,primary_key=True,verbose_name="订单编号")
    payment = models.DecimalField(max_digits=10,decimal_places=2,verbose_name="车辆价格")
    post_fee = models.DecimalField(max_digits=10,decimal_places=2,verbose_name="运费")
    payment_type = models.IntegerField(choices=payment_type_choice,verbose_name='支付方式')
    status = models.IntegerField(choices=order_status,verbose_name='订单状态')
    create_time = models.DateTimeField(verbose_name='订单创建时间')
    update_time = models.DateTimeField(verbose_name='订单更新时间')
    payment_time = models.DateTimeField(verbose_name='付款时间')
    consign_time = models.DateTimeField(verbose_name='发货时间')
    end_time = models.DateTimeField(verbose_name='交易完成时间')
    buyer_msg = models.CharField(max_length=100,verbose_name='买家留言')
    buyer = models.ForeignKey('user.Info',verbose_name='买家',on_delete=models.CASCADE)
    buyer_rate = models.IntegerField(verbose_name='买家是否已经评价（1未评价，2已评价）',default=1)

    class Meta:
        db_table = 'tb_order'
        verbose_name = '订单信息'
        verbose_name_plural = verbose_name

class OrderCar(models.Model):
    order_id = models.OneToOneField('Order',on_delete=models.CASCADE,verbose_name='订单编号')
    car_id = models.ForeignKey('cars.Info',on_delete=models.CASCADE,verbose_name='车辆编号')
    user_id = models.ForeignKey('user.Info',on_delete=models.CASCADE,verbose_name='客户编号')

    class Meta:
        db_table = 'tb_order_car'
        verbose_name = '订单车辆'
        verbose_name_plural = verbose_name


class OrderShipping(models.Model):
    order_id = models.OneToOneField('Order', on_delete=models.CASCADE,verbose_name='订单编号')
    shipping_name = models.ForeignKey('shipping.Info',on_delete=models.CASCADE,verbose_name='物流公司')
    shipping_id = models.CharField(max_length=50,verbose_name='物流单号')
    order_recv = models.OneToOneField('user.RecvInfo',on_delete=models.CASCADE,verbose_name='收货人信息')
    create = models.DateTimeField(verbose_name='创建时间')
    update = models.DateTimeField(verbose_name='更新时间')

    class Meta:
        db_table = 'tb_order_shipping'
        verbose_name = '订单物流'
        verbose_name_plural = verbose_name

